<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //
        Route::pattern('id', '[0-9]+');
        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapAdminRoutes();
        $this->mapTouchRoutes();
        $this->mapWechatRoutes();
    }

    /**
     * 后台路由配置
     * @return [type] [description]
     */
    protected function mapAdminRoutes(){
        Route::middleware('web')
             ->namespace($this->namespace.'\Admin')
             ->group(base_path('routes/admin/admin.php'));
        Route::middleware('web')
             ->namespace($this->namespace.'\AuthAdmin')
             ->group(base_path('routes/admin/auth.php'));

        $this->mapAdminConfig();
        $this->mapAdminPerson();
        $this->mapAdminWechat();
    }
    /**
     * 微信路由
     * @return [type] [description]
     */
    protected function mapWechatRoutes(){
        $nameSpace = Route::middleware('web')->namespace($this->namespace);
        $nameSpace->group(base_path('routes/wechat.php'));
    }

    /**
     * 后台用户管理
     * @return [type] [description]
     */
    private function mapAdminPerson(){
        $nameSpace = Route::middleware('web')->namespace($this->namespace.'\Admin\Persons');
        $nameSpace->group(base_path('routes/admin/persons/person.php'));

    }
    /**
     * 后台系统配置
     * @return [type] [description]
     */
    private function mapAdminConfig(){
        $nameSpace = Route::middleware('web')->namespace($this->namespace.'\Admin\Config');
        $nameSpace->group(base_path('routes/admin/config/permission.php'));
        $nameSpace->group(base_path('routes/admin/config/category.php'));
        $nameSpace->group(base_path('routes/admin/config/role.php'));
        $nameSpace->group(base_path('routes/admin/config/admin.php'));
        $nameSpace->group(base_path('routes/admin/config/config.php'));
        $nameSpace->group(base_path('routes/admin/config/smstpl.php'));
        $nameSpace->group(base_path('routes/admin/config/record.php'));
        $nameSpace->group(base_path('routes/admin/config/banner.php'));
    }

    private function mapAdminWechat(){
        $nameSpace = Route::middleware('web')->namespace($this->namespace.'\Admin\Wechat');
        $nameSpace->group(base_path('routes/admin/wechat/function/reply.php'));
        $nameSpace->group(base_path('routes/admin/wechat/function/menu.php'));
        $nameSpace->group(base_path('routes/admin/wechat/function/customer.php'));
        
        $nameSpace->group(base_path('routes/admin/wechat/manager/material.php'));
        $nameSpace->group(base_path('routes/admin/wechat/manager/user.php'));
        
    }

    /**
     * 手机版路由配置
     * @return [type] [description]
     */
    protected function mapTouchRoutes(){
        Route::middleware('web')
             ->namespace($this->namespace.'\Touch')
             ->group(base_path('routes/touch/touch.php'));
        Route::middleware('web')
             ->namespace($this->namespace.'\Auth')
             ->group(base_path('routes/touch/auth.php'));

        Route::middleware('web')
             ->namespace($this->namespace.'\Touch\Home')
             ->group(base_path('routes/touch/home/index.php'));
    }


    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}
